package com.wind.httpProxyServer.proxy;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

import com.wind.httpProxyServer.constants.HttpResponseStatus;
import com.wind.httpProxyServer.httpMessage.HttpRequestMessage;
import com.wind.httpProxyServer.httpMessage.HttpResponseMessage;
import com.wind.httpProxyServer.utils.SocketUtil;

/**
 * 代理服务端
 * 
 * @author qq
 *
 */
public class ServerProxy extends Proxy {

	public ServerProxy(Socket clientSocket, Socket serverSocket, HttpRequestMessage requestMessage) {
		super(clientSocket, serverSocket, requestMessage);
	}

	@Override
	public void proxyHttps() {
		/*
		 * 响应客户端Web隧道建立成功
		 */
		HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpResponseStatus._200);
		httpResponseMessage.addHeader("Connection", "close");
		httpResponseMessage.addHeader("Access-Control-Allow-Origin:", "*");
//		httpResponseMessage.addHeader("Access-Control-Allow-Origin", "*");
		httpResponseMessage.addHeader("Access-Control-Allow-Methods", "*");
		httpResponseMessage.addHeader("Access-Control-Allow-Headers", "*");

//		String corsHeaders = "HTTP/1.1 200 OK\r\n" +
//				"Access-Control-Allow-Origin: *\r\n" +
//				"Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n" +
//				"Access-Control-Allow-Headers: Content-Type, Authorization\r\n" +
//				"Content-Length: 0\r\n" +
//				"\r\n";

		SocketUtil.writeSocket(super.clientOutputStream, httpResponseMessage, super.isEncryptResponse());

		super.proxyHttps();
	}

}
